package com.adou.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.adou.demo.common.constant.CommResultCode;
import com.adou.demo.common.constant.ResponseDTO;
import com.adou.demo.common.controller.BaseController;
import com.adou.demo.entity.User;
import com.adou.demo.service.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequestMapping("/")
@Api(value = "UserController", description = "用户接口")
public class UserController extends BaseController {
	@Autowired
	private UserService userService;
	
	@ApiOperation(value="用户查询", notes="根据用户名查询")
    @ApiImplicitParams({
          @ApiImplicitParam(name = "name", value = "用户名", required = true ,dataType = "string"),
    })
	@PostMapping(value = "/users/{name}")
	public ResponseDTO<?> findByName(@PathVariable("name") String name) {
		log.info("====================== name: " + name);
		ResponseDTO<?> response = null;
		try {
			User  user = userService.findByName(name);
			response = onSuccess(user);
		} catch (Exception e) {
			onFailedBiz(CommResultCode.SYSTEM_ERROR);
			log.error("e:{}", e);
		}
		
		log.info("====================== response: " + response);
		return response;
	}

}
